	//tree结构的图片
	function globalVars (imagedir){
		//Imgages
		this.imagedir = imagedir;
						
		this.plusImg = this.imagedir + "plus.gif";
		this.plusdownImg = this.imagedir + "plusdown.gif";
		this.plusupImg = this.imagedir + "plusup.gif";
		
		this.singleupImg = this.imagedir  + "singleup.gif";
		this.singledownImg = this.imagedir  + "singledown.gif";
				
		this.minusImg = this.imagedir  + "minus.gif";
		this.minusupImg = this.imagedir  + "minusup.gif";
		this.minusdownImg = this.imagedir  + "minusdown.gif";
		
		this.blankImg = this.imagedir + "blank.gif";
		this.blankupImg = this.imagedir + "blankup.gif";
		this.blankdownImg = this.imagedir + "blankdown.gif";
		
		this.emptyImg = this.imagedir + "empty.gif";
		this.emptyImgNode = "<IMG SRC='" + this.emptyImg + "' WIDTH='16' HEIGHT='18' Border='0'>";
		this.lineImg = this.imagedir + "line.gif";
		this.lineImgNode = "<IMG SRC='" + this.lineImg + "' WIDTH='16' HEIGHT='18' Border='0'>";
		
		this.createImgNode = function (src) {
			var o = document.createElement("img");
			o.src = src;
			o.style.width = "16";
			o.style.height = "18";
			o.style.border = "0";
			o.style.cursor = "hand";
			return o;
		}
	}
	var gVars = new globalVars(globeWebAppContext + "/brick/image/");
	
	//树状信息节点的数据结构
	function TreeNode (treeObj) {
		this.index = 0;					//节点主键
		this.parent = -1;				//父节点
		this.primaryKey = "";			//业务主键
		this.parentKey = "";			//父节点的业务主键
		this.sibling = -1;				//sibling index; -1 
		this.last = -1					// the last child, -1 no child
		this.child = -1;				// -1 represent no child;
		this.text = "";					//html str
		this.folded = true;			//是否收缩的情况
		
		this.tableObj = null;
		this.imgObj = null;
		this.preContentObj = null;
		this.contentObj = null;
		this.childrenObj = null;
		
		this.fetched = true;			//是否从后台提取过信息，当是lazyloading的时候才有效
		
		this.treeObj = treeObj;
	}
	
	TreeNode.prototype.reset = function () {
		this.folded = true;
		
		this.tableObj = null;
		this.imgObj = null;
		this.preContentObj = null;
		this.contentObj = null;
		this.childrenObj = null;
	}
	
	TreeNode.prototype.refreshImage = function () {
		this.preContentObj.innerHTML = "";
		this.preContentObj.innerHTML = this.getPreImage();
		this.imgObj = this.getNowImage();
		this.preContentObj.appendChild(this.imgObj);
		
		var oThis = this;
		this.imgObj.onclick = function () {
			oThis.expand();
			if (typeof oThis.onexpand == "function") {
				oThis.onexpand();
			}
		}
	}
	
	TreeNode.prototype.getNowImage = function () {
		var nowimg = "";
		//not child
		if (this.child == -1) {
			if (this.index == 0) {			//first one!
				if (this.treeObj.needFetch && !this.fetched)
					 nowimg = gVars.plusupImg;
				else
					 nowimg = gVars.blankupImg;
			} else {
				if (this.sibling == -1) {			//last one!
				    if (this.treeObj.needFetch && !this.fetched)
				  	  	nowimg = gVars.plusdownImg;
					else
						nowimg = gVars.blankdownImg;
				} else {
		            if (this.treeObj.needFetch && !this.fetched)
						nowimg = gVars.plusImg;
					else
						nowimg = gVars.blankImg;
				}
			}
		//has child
		} else {
			if (this.index == 0) {			//first one!
				if (this.sibling == -1)		//Only one
					nowimg = gVars.singleupImg;
				else 
					nowimg = (this.folded)?gVars.plusImg:gVars.minusImg;
			} else {
				if(this.sibling == -1)			//last one!
					nowimg = (this.folded)?gVars.plusdownImg:gVars.minusdownImg;
				else
					nowimg = (this.folded)?gVars.plusImg:gVars.minusImg;
			}
		}
		return gVars.createImgNode(nowimg);
	};
	
	TreeNode.prototype.getPreImage = function () {
		//计算层次
		var temp = this;
		var level = 1;
		while (temp.parent != 0) {
			level++;
			temp = this.treeObj.nodelist[temp.parent];
		}
		
		//组合imge
		var html = "";
		for (var i = 1; i < level; i++) {
			temp = this;
			for (var j = 0; j < level - i - 1; j++)
				temp = this.treeObj.nodelist[temp.parent];
			
			if (this.treeObj.nodelist[temp.parent].sibling != -1)
				html += gVars.lineImgNode;
			else
				html += gVars.emptyImgNode;
		}
		return html;
	};
	
	TreeNode.prototype.create = function () {
		this.tableObj = document.createElement("table");
		this.tableObj.cellSpacing = "0";
		this.tableObj.cellPadding = "0";
		
		var tBody = document.createElement( "tbody" );
		this.tableObj.appendChild(tBody);
		
		var tr = document.createElement("tr");
		tBody.appendChild(tr);
		
		//节点内容前的image
		this.preContentObj = document.createElement("td");
		this.preContentObj.noWrap = true;
		this.preContentObj.innerHTML = this.getPreImage();
		this.imgObj = this.getNowImage();
		this.preContentObj.appendChild(this.imgObj);
		tr.appendChild(this.preContentObj);
		
		
		//节点内容
		this.contentObj = document.createElement("td");
		this.contentObj.width = "100%";
		this.contentObj.noWrap = true;
		this.contentObj.innerHTML = this.text;
		tr.appendChild(this.contentObj);
		
		
		//子节点
		tr = document.createElement("tr");
		tBody.appendChild(tr);
		
		this.childrenObj = document.createElement("td");
		this.childrenObj.colSpan = 2;
		this.childrenObj.noWrap = true;
		this.childrenObj.style.display = "none";
		tr.appendChild(this.childrenObj);
		
		//event
		var oThis = this;
		this.contentObj.onclick = function () {
			if (typeof oThis.onclick == "function") {
				oThis.onclick();
			}
			
			if (typeof oThis.treeObj.onclick == "function") {
				oThis.treeObj.onclick(oThis);
			}
			
			if (typeof oThis.treeObj.onfocus == "function") {
				oThis.treeObj.onfocus(oThis);
			}
		}
		
		this.imgObj.onclick = function () {
			if (oThis.treeObj.disabled) return;
			oThis.expand();
			if (typeof oThis.onexpand == "function") {
				oThis.onexpand();
			}
		}
	}
	
	TreeNode.prototype.expand = function () {
		var nowimg = "";
		
		//lazy loading树节点
		if (this.treeObj.needFetch && !this.fetched) {
			this.treeObj.fetchContent(this.primaryKey);
			this.fetched = true;
		}
		
		//有子节点，找到其中一个，看看tableObj是否有，没有需要生成之
		if (this.child != -1) {
			this.folded = !this.folded;
			this.treeObj.createNodeFromParent(this.index);
		}
		
		
		//切换隐藏状态和图片
		if (this.folded == false) {
			if (this.child != -1) {			//has child
				if (this.index == 0) {			//first one!
					if (this.sibling == -1)
						nowimg = gVars.singledownImg;
					else
						nowimg = gVars.minusupImg;
				} else {
					if (this.sibling == -1)			//last one!
						nowimg = gVars.minusdownImg;
					else
						nowimg = gVars.minusImg;			 
				}
				if (this.index != 0) { 	  
					this.childrenObj.style.display = "";		//To display		  	  
					this.imgObj.src = nowimg;	 
				}						 
			}		
		} else {
			if (this.child != -1) {
				if (this.index == 0) {			//first one!
					if (this.sibling == -1)
						nowimg = gVars.singleupImg;
					else
						nowimg = gVars.plusupImg;
				} else {
					if (this.sibling == -1)			//last one!
						nowimg=gVars.plusdownImg;
					else
						nowimg=gVars.plusImg;
				}
				this.childrenObj.style.display = "none";		//To hide	  
				this.imgObj.src = nowimg;		//Can't put at the bottom Coz the nowimg can be empty!
			}
		}
	}
	
	//构造函数
	function Tree (id) {
		this.nodelist = new Array();
		this.id = id;
		this.contain = document.getElementById(id + ".contain");
		this.needFetch = (this.contain.getAttribute("lazyLoading") != null);
		this.disabled = false;
		
		//动态获取content的相关参数
		this.url = this.contain.getAttribute("url");
		this.content = this.contain.getAttribute("content");
		
		if (this.url == null && this.content != null) {
			//需要根据个各项目定义的通用获取option的链接
			this.url = "/content.xml?content=" + this.content;
		}
		this.method = this.contain.getAttribute("method");
		this.primaryKeyProperty = this.contain.getAttribute("primaryKeyProperty");
		this.parentKeyProperty = this.contain.getAttribute("parentKeyProperty");
		this.textProperty = this.contain.getAttribute("textProperty");
				
		//记录dependon的参数
		this.param = {};
		this.free = {};
		this.removeParam = function (paramName) {
			if (paramName && paramName != "")
				delete this.param[paramName];
		};
		this.setParam = function (paramName, paramValue) {	
			if (paramName && paramName != "" && paramValue && paramValue != "") {
				this.param[paramName] = paramValue;
			}
		};
		this.getParam = function () {
			return hashToParam(this.param);
		}
		this.isFree = function () {
			return hashToBool(this.free);
		}
		
		
		//初始化根节点
		this.addNode("##_root_##", -1, "root");
		this.nodelist[0].fetched = true;
	}
	
	//是否是祖先
	Tree.prototype.isAncestor = function (c, a) {
		if (a == 0) return true;
		
		var tempnode = this.nodelist[c];
		while (tempnode && tempnode.parent != 0) {
			if (tempnode.parent == a) return true;
			tempnode = this.nodelist[tempnode.parent];
		}
		return false;
	}
	
	//按照数据节点展开一个节点
	Tree.prototype.expandNode = function (index) {
		var tempnode = this.nodelist[index];
		if (tempnode) {
			this.expandNode(tempnode.parent);
			tempnode.expand();
		}
	}
	
	//按照业务节点展开一个节点
	Tree.prototype.expandNodeByPrimaryKey = function (primaryKey) {		
		for (j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == primaryKey) {
				this.expandNode(j);
				break;
			}
		}
	}
	//创建一个父节点的所有子节点html
	//只有一层
	Tree.prototype.createNodeFromParent = function (parent) {
		var pnode = this.nodelist[parent];
		
		if (pnode.child != -1) {
			var endsibling = -1;
			var tempnode = this.nodelist[pnode.child];
			do {
				
				//如果没有，创建
				if (tempnode.tableObj == null) tempnode.create();
				//添加
				if (parent != 0 && pnode.childrenObj) {
					pnode.childrenObj.appendChild(tempnode.tableObj);
				} else {
					this.contain.appendChild(tempnode.tableObj);
				}
				
				endsibling = tempnode.sibling;
				tempnode = this.nodelist[tempnode.sibling];
			} while (endsibling != -1)
		}
	}
	
	//根据业务主键来创建
	Tree.prototype.createNodeFromParentByPrimaryKey = function (parentKey) {
		for (var j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == parentKey) {
				this.createNodeFromParent(j)
				break;
			}
		}	
	}
	
	//显示第一层的节点,够造好一颗树后必调的方法
	Tree.prototype.create = function () {
		this.createNodeFromParent(0);
	}
	
	//刷新某个父节点的所有子节点的image
	Tree.prototype.refreshNodeFromParent = function (parent) {
		var pnode = this.nodelist[parent];
		if (pnode.child != -1) {
			var endsibling = -1;
			var tempnode = this.nodelist[pnode.child];
			do {
				
				//如果没有创建，那么不刷新
				if (tempnode.tableObj != null) {
					tempnode.refreshImage();
					this.refreshNodeFromParent(tempnode.index);
				}
				
				endsibling = tempnode.sibling;
				tempnode = this.nodelist[tempnode.sibling];
			} while (endsibling != -1)
		}
	}
	
	//根据业务主键来刷新
	Tree.prototype.refreshNodeFromParentByPrimaryKey = function (parentKey) {
		for (var j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == parentKey) {
				this.refreshNodeFromParent(j)
				break;
			}
		}	
	}
	
	//通过treenode的主键来增加节点
	Tree.prototype.addNode = function (primaryKey, parent, text) {
		var i;
		var tempnode;
				
		i = this.nodelist.length;
		
		this.nodelist[i] = new TreeNode(this);
		
		this.nodelist[i].index = i;
		
		if (primaryKey)
			this.nodelist[i].primaryKey = primaryKey;
		
		this.nodelist[i].parent = parent;
		if (this.nodelist[parent])
			this.nodelist[i].parentKey = this.nodelist[parent].primaryKey;
		
		this.nodelist[i].text = text.trim();
		this.nodelist[i].fetched = !this.needFetch;


		
		var previous = -1;						
		//not root node
		if (i > 0) {
			//the node's parent has no any child
			if (this.nodelist[parent].child == -1) {
				this.nodelist[parent].child = i;
				this.nodelist[parent].last = i;
			//the node's parent has child
			} else {
				previous = this.nodelist[parent].last
				//get the curr parent' last child set the old last's sibling
				this.nodelist[this.nodelist[parent].last].sibling = i;
				//set the new last
				this.nodelist[parent].last = i;
			}	
		}
		
		//如果父节点已经构建,刷新一下父节点的img
		if (parent != -1 && this.nodelist[parent].tableObj != null) {
			this.nodelist[parent].refreshImage();
		}
		//如果该节点的上一个节点已经构建,刷新一下,然后构建一下本身的节点
		//还需要将该节点的上一个节点的所有子节点的image全部重新构建
		if (previous != -1 && this.nodelist[previous].tableObj != null) {
			this.nodelist[previous].refreshImage();
			this.nodelist[i].create();
			//不是根节点
			if (parent != 0)
				this.nodelist[parent].childrenObj.appendChild(this.nodelist[i].tableObj);
			else
				this.contain.appendChild(this.nodelist[i].tableObj);
				
			//刷新前一个节点的所有子节点的图片
			this.refreshNodeFromParent(previous);
			
		}
	}
	
	//通过业务主键来增加节点
	Tree.prototype.addNodeByPrimaryKey = function (primaryKey, parentKey, text) {
		for (var j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == parentKey) {
				this.addNode(primaryKey, j, text)
				return;
			}
		}
		
		if (parentKey == null) this.addNode(primaryKey, 0, text);
	}
	
	//通过主键在某个子节点下增加一个新节点
	Tree.prototype.addNodeUnderChild = function (primaryKey, child, text) {
		//同级存在
		if (this.nodelist[child]) {
			//共同的父亲
			var parent = this.nodelist[child].parent;
			this.addNode(primaryKey, parent, text);
			//当前新增的节点
			temp = this.nodelist[this.nodelist.length - 1];
			//上移新增的节点			
			while (this.nodelist[child].sibling != temp.index) {
				this.moveUpNode(temp.index);
			}
		} else {
			return;
		}
	}
	
	//通过业务主键在某个子节点下增加一个新节点
	Tree.prototype.addNodeUnderChildByPrimaryKey = function (primaryKey, childKey, text) {
		for (var j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == childKey) {
				this.addNodeUnderChild(primaryKey, j, text);
				return;
			}
		}
	}
	
	//通过节点主键在update一个节点，如果该节点存在那么update,如果该节点不存在那么新增
	Tree.prototype.saveOrUpdateNode = function (index, primaryKey, parent, text) {
		if (this.nodelist[index]) {
			this.nodelist[index].text = text.trim();
			if (this.nodelist[index].tableObj != null)
				this.nodelist[index].contentObj.innerHTML = text.trim();
			
		} else if (parent) {
			this.addNode(primaryKey, parent, text);
		} else {
			return;
		}
	}
	
	//通过业务主键在update一个节点，如果该节点存在，那么update，如果该节点不存在那么新增一个
	Tree.prototype.saveOrUpdateNodeByPrimaryKey = function (primaryKey, parentKey, text) {
		var parent = -2;
		for (var j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == primaryKey) {
				this.saveOrUpdateNode(j, primaryKey, this.nodelist[j].parent, text);
				return;
			} else if (this.nodelist[j] && this.nodelist[j].primaryKey == parentKey) {
				parent = j;
			}
		}
		
		if (parentKey && parent != -2) {
			this.saveOrUpdateNode(-1, primaryKey, parent, text);
		}
	}
	
	//移动树上的某个节点到新的父节点下	
	//通过节点主键来移动
	Tree.prototype.moveNode = function (index, parent) {
		//被剪切的节点是父节点的祖先
		if (this.isAncestor(parent, index)) return;
		
		if (this.nodelist[index] && this.nodelist[parent]) {
			//从以前节点下移去
			//not the first node
			var oldParent = this.nodelist[index].parent, oldPrevious = -1, newPrevious = -1;
			if (this.nodelist[this.nodelist[index].parent].child != index) {
				//the parent node
				temp = this.nodelist[this.nodelist[this.nodelist[index].parent].child];	
				//find the index node's pre node
				while (temp.sibling != index)
					temp = this.nodelist[temp.sibling];
				//set the temp node's sibling is the index nodes' sibling
				temp.sibling = this.nodelist[index].sibling;
				//if index node is the last node
				if (temp.sibling == -1) {
					this.nodelist[this.nodelist[index].parent].last = temp.index;
					oldPrevious = temp.index;
				}
			//is the first node
			} else {
				//set the parent's child is the index node's sibling
				this.nodelist[this.nodelist[index].parent].child = this.nodelist[index].sibling;
				//if index node is the last node
				if (this.nodelist[index].sibling == -1) {
					this.nodelist[this.nodelist[index].parent].last = -1
				}
			}
			
			
			//加入新的父亲下
			this.nodelist[index].sibling = -1;
			this.nodelist[index].parent = parent;
			//parent's has child
			if (this.nodelist[parent].child != -1) {
				newPrevious = this.nodelist[parent].last;
				this.nodelist[this.nodelist[parent].last].sibling = index;
				this.nodelist[parent].last = index;
			} else {
				this.nodelist[parent].child = index;
				this.nodelist[parent].last = index;
			}
			
			//如果被移动的节点已经被创建
			if (this.nodelist[index].tableObj != null) {
				this.nodelist[index].tableObj.removeNode(true);
				//如果同级节点已经有了，且被创建
				if (newPrevious != -1 && this.nodelist[newPrevious].tableObj != null) {
					this.nodelist[index].refreshImage();
					this.refreshNodeFromParent(index);
					//不是根节点
					if (parent != 0)
						this.nodelist[parent].childrenObj.appendChild(this.nodelist[index].tableObj);
					else
						this.contain.appendChild(this.nodelist[index].tableObj);
				//如果统计的节点无或者没有创建，清空当前节点的信息
				} else {
					this.nodelist[index].reset();
					this.resetFromParent(index);
				}
			//被移动的节点没有被创建
			} else {
				//如果同级节点已经有了，且被创建
				if (newPrevious != -1 && this.nodelist[newPrevious].tableObj != null) {
					this.nodelist[index].create();
					//不是根节点
					if (parent != 0)
						this.nodelist[parent].childrenObj.appendChild(this.nodelist[index].tableObj);
					else
						this.contain.appendChild(this.nodelist[index].tableObj);
				}
			}
			
			//如果老父亲已经创建
			if (this.nodelist[oldParent].tableObj != null) {
				this.nodelist[oldParent].refreshImage();
			}
			//如果老的前一个节点是最后一个，也需要刷新
			if (oldPrevious != -1 && this.nodelist[oldPrevious].tableObj != null) {
				this.nodelist[oldPrevious].refreshImage();
				this.refreshNodeFromParent(oldPrevious);
			}
			
			//如果新的父亲已经创建
			if (this.nodelist[parent].tableObj != null) {
				this.nodelist[parent].refreshImage();
			}
			//如果新的节点的前一个节点已经创建
			if (newPrevious != -1 && this.nodelist[newPrevious].tableObj != null) {
				this.nodelist[newPrevious].refreshImage();
				this.refreshNodeFromParent(newPrevious);
			}
			
		} else {
			return;
		}
	}
	
	//移动树上的某个节点到新的父节点下
	//通过业务主键来移动
	Tree.prototype.moveNodeByPrimaryKey = function (primaryKey, parentKey) {
		var hasFound = 0;
		var index = -1, parent = -1;
		for (var j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == primaryKey) {
				index = j;
				hasFound++;
			} else if (this.nodelist[j] && this.nodelist[j].primaryKey == parentKey) {
				parent = j;
				hasFound++;
			}
			if (hasFound == 2) break;
		}		
		if (index != -1 && parent != -1)
			this.moveNode(index, parent);
	}


	//移动树上的某个节点到新的子节点的下面
	//通过节点主键来移动
	Tree.prototype.moveNodeUnderChild = function (index, child) {
		//被剪切的节点是子节点的祖先
		if (this.isAncestor(parent, index)) return;
		
		if (this.nodelist[index] && this.nodelist[child]) {
			//从以前节点下移去
			//not the first node
			var oldParent = this.nodelist[index].parent, oldPrevious = -1, newParent = this.nodelist[child].parent;
			if (this.nodelist[this.nodelist[index].parent].child != index) {
				//the parent node
				temp = this.nodelist[this.nodelist[this.nodelist[index].parent].child];	
				//find the index node's pre node
				while (temp.sibling != index)
					temp = this.nodelist[temp.sibling];
				//set the temp node's sibling is the index nodes' sibling
				temp.sibling = this.nodelist[index].sibling;
				//if index node is the last node
				if (temp.sibling == -1) {
					this.nodelist[this.nodelist[index].parent].last = temp.index;
					oldPrevious = temp.index;
				}
			//is the first node
			} else {
				//set the parent's child is the index node's sibling
				this.nodelist[this.nodelist[index].parent].child = this.nodelist[index].sibling;
				//if index node is the last node
				if (this.nodelist[index].sibling == -1) {
					this.nodelist[this.nodelist[index].parent].last = -1
				}
			}
			
			//加入新的儿子的下面
			this.nodelist[index].sibling = -1;
			this.nodelist[index].parent = this.nodelist[child].parent;
			//child is not the last
			if (this.nodelist[child].sibling != -1) {
				this.nodelist[index].sibling = this.nodelist[child].sibling;
				this.nodelist[child].sibling = index;
			} else {
				this.nodelist[child].sibling = index;
				this.nodelist[this.nodelist[child].parent].last = index;
			}
			
			
			//如果被移动的节点已经被创建
			if (this.nodelist[index].tableObj != null) {
				this.nodelist[index].tableObj.removeNode(true);
				//如果同级节点已经有了，且被创建
				if (this.nodelist[child].tableObj != null) {
					this.nodelist[index].refreshImage();
					this.refreshNodeFromParent(index);
					this.nodelist[child].tableObj.insertAdjacentElement("afterEnd", this.nodelist[index].tableObj);
				//如果统计的节点无或者没有创建，清空当前节点的信息
				} else {
					this.nodelist[index].reset();
					this.resetFromParent(index);
				}
			//被移动的节点没有被创建
			} else {
				//如果同级节点已经有了，且被创建
				if (this.nodelist[child].tableObj != null) {
					this.nodelist[index].create();
					this.nodelist[child].tableObj.insertAdjacentElement("afterEnd", this.nodelist[index].tableObj);
				}
			}
			
			//如果老父亲已经创建
			if (this.nodelist[oldParent].tableObj != null) {
				this.nodelist[oldParent].refreshImage();
			}
			//如果老的前一个节点是最后一个，也需要刷新
			if (oldPrevious != -1 && this.nodelist[oldPrevious].tableObj != null) {
				this.nodelist[oldPrevious].refreshImage();
				this.refreshNodeFromParent(oldPrevious);
			}
			
			//如果新的父亲已经创建
			if (this.nodelist[newParent].tableObj != null) {
				this.nodelist[newParent].refreshImage();
			}
			//如果新的节点的前一个节点已经创建，并且当前节点是最后一个
			if (this.nodelist[child].tableObj != null && this.nodelist[index].sibling == -1) {
				this.nodelist[child].refreshImage();
				this.refreshNodeFromParent(child);
			}
		} else {
			return;
		}
	}
	
	//移动树上的某个节点到新的子节点下
	//通过业务主键来移动
	Tree.prototype.moveNodeUnderChildByPrimaryKey = function (primaryKey, childKey) {
		var hasFound = 0;
		var index = -1, child = -1;
		for (var j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == primaryKey) {
				index = j;
				hasFound++;
			} else if (this.nodelist[j] && this.nodelist[j].primaryKey == childKey) {
				child = j;
				hasFound++;
			}
			if (hasFound == 2) break;
		}		
		if (index != -1 && child != -1)
			this.moveNodeUnderChild(index, child);
	}

	
	//用节点主键上移某个节点
	Tree.prototype.moveUpNode = function (index) {
		if (this.nodelist[index]) {
			//not the first node
			if (this.nodelist[this.nodelist[index].parent].child != index) {
				//the parent node
				var temp = this.nodelist[this.nodelist[this.nodelist[index].parent].child];	
				//find the index node's pre node
				while (temp.sibling != index)
					temp = this.nodelist[temp.sibling];
				//if the temp is not first	
				if (this.nodelist[this.nodelist[index].parent].child != temp.index) {
					//find the up node's up node
					var temp1 = this.nodelist[this.nodelist[this.nodelist[index].parent].child];
					while (temp1.sibling != temp.index)
						temp1 = this.nodelist[temp1.sibling];
					
					temp.sibling = this.nodelist[index].sibling;
					this.nodelist[index].sibling = temp.index;
					temp1.sibling = index;
						
				//temp is the first
				} else {
					temp.sibling = this.nodelist[index].sibling;
					this.nodelist[index].sibling = temp.index;
					this.nodelist[this.nodelist[index].parent].child = index;
				}
				//if index is the last
				if (this.nodelist[this.nodelist[index].parent].last == index)
					this.nodelist[this.nodelist[index].parent].last = temp.index;
					
				//交换两个节点
				if (this.nodelist[index].tableObj != null && temp.tableObj != null) {
					this.nodelist[index].tableObj.swapNode(temp.tableObj);
					
					//如果恰好是最后两个，那么需要刷信image
					if (temp.sibling == -1) {
						this.nodelist[index].refreshImage();
						temp.refreshImage();
						this.refreshNodeFromParent(index);
						this.refreshNodeFromParent(temp.index);
					}
				}
			//first node		
			} else {
				return;
			}				
		} else {
			return;
		}
	}
	
	//用业务主键上移某个节点
	Tree.prototype.moveUpNodeByPrimaryKey = function (primaryKey) {
		var index = -1;
		for (var j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == primaryKey) {
				index = j;
				break;
			}
		}
		if (index != -1)
			this.moveUpNode(index);
	}
	
	//通过节点主键下移某个节点
	Tree.prototype.moveDownNode = function (index) {
		if (this.nodelist[index]) {
			//is not the tail node
			if (this.nodelist[index].sibling != -1) {
				temp = this.nodelist[this.nodelist[index].sibling];
				//not the first node
				if (this.nodelist[this.nodelist[index].parent].child != index) {
					var temp1 = this.nodelist[this.nodelist[this.nodelist[index].parent].child];
					while (temp1.sibling != index)
						temp1 = this.nodelist[temp1.sibling];
					
					this.nodelist[index].sibling = temp.sibling;
					temp.sibling = index;
					temp1.sibling = temp.index;
					
				//first node
				} else {
					this.nodelist[index].sibling = temp.sibling;
					temp.sibling = index;
					this.nodelist[this.nodelist[index].parent].child = temp.index;
				}
				
				//temp is the last
				if (this.nodelist[this.nodelist[index].parent].last == temp.index)
					this.nodelist[this.nodelist[index].parent].last = index;
				
				//交换两个节点
				if (this.nodelist[index].tableObj != null && temp.tableObj != null) {
					this.nodelist[index].tableObj.swapNode(temp.tableObj);
					
					//如果恰好是最后两个，那么需要刷信image
					if (this.nodelist[index].sibling == -1) {
						this.nodelist[index].refreshImage();
						temp.refreshImage();
						this.refreshNodeFromParent(index);
						this.refreshNodeFromParent(temp.index);
					}
				}
			} else {
				return;
			}
		} else {
			return;
		}
	}
	
	//通过业务主键下移某个节点通过主键完成
	Tree.prototype.moveDownNodeByPrimaryKey = function (primaryKey) {
		var index = -1;
		for (var j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == primaryKey) {
				index = j;
				break;
			}
		}
		if (index != -1)
			this.moveDownNode(index);
	
	}
	
	//通过节点主键移除某个节点
	Tree.prototype.removeNode = function (index) {		
		
		if (this.nodelist[index]) {
			var previous = -1;
			var parent = this.nodelist[index].parent;
			//not the first node
			if (this.nodelist[this.nodelist[index].parent].child != index) {
				//the parent node
				var temp = this.nodelist[this.nodelist[this.nodelist[index].parent].child];	
				//find the index node's pre node
				while (temp.sibling != index)
					temp = this.nodelist[temp.sibling];
				
				//set the temp node's sibling is the index nodes' sibling
				temp.sibling = this.nodelist[index].sibling;
				//if index node is the last node
				if (temp.sibling == -1) {
					//need to refresh pre image
					previous = temp.index;
					this.nodelist[this.nodelist[index].parent].last = temp.index;
				}
			//is the first node
			} else {
				//set the parent's child is the index node's sibling
				this.nodelist[this.nodelist[index].parent].child = this.nodelist[index].sibling;
				//if index node is the last node
				if (this.nodelist[index].sibling == -1) {
					this.nodelist[this.nodelist[index].parent].last = -1
				}
			}
			
			
			//如果已经构建过了，需要将tableObj移除
			if (this.nodelist[index].tableObj != null) {
				this.nodelist[index].tableObj.removeNode(true);
				
				//如果pre不是-1，那么前面的节点需要刷新
				if (previous != -1) {
					this.nodelist[previous].refreshImage();
					this.refreshNodeFromParent(previous);
				}
			}
			
			//如果父节点构建过，同样需要刷新
			if (parent > 0 && this.nodelist[parent].tableObj != null) {
				this.nodelist[parent].refreshImage();
			}
			
			//delete the index node
			this.removeFromParent(index);
			this.nodelist[index] = this.nodelist[-1];
		}
	}
	
	//通过业务主键移除某个节点
	Tree.prototype.removeNodeByPrimaryKey = function (primaryKey) {
		for (var j = 0;j < this.nodelist.length; j++) {
			if (this.nodelist[j] && this.nodelist[j].primaryKey == primaryKey) {
				this.removeNode(j);
				return;
			}
		}
	}
	
	//滞空一个节点的所有子节点
	Tree.prototype.removeFromParent = function (parent) {
		var pnode = this.nodelist[parent];
		var index = 0;
		if (pnode.child != -1) {
			var endsibling = -1;
			var tempnode = this.nodelist[pnode.child];
			do {
				endsibling = tempnode.sibling;
				this.removeFromParent(tempnode.index);
				index = tempnode.index;
				tempnode = this.nodelist[tempnode.sibling];
				
				this.nodelist[index] = this.nodelist[-1];
				
			} while (endsibling != -1)
		}
	}
	
	//滞空一个节点的所有子节点所包含的对象
	Tree.prototype.resetFromParent = function (parent) {
		var pnode = this.nodelist[parent];
		var index = 0;
		if (pnode.child != -1) {
			var endsibling = -1;
			var tempnode = this.nodelist[pnode.child];
			do {
				this.resetFromParent(tempnode.index);
				tempnode.reset();
				
				endsibling = tempnode.sibling;
				tempnode = this.nodelist[tempnode.sibling];				
			} while (endsibling != -1)
		}
	}
	
	
	//获取选项
	Tree.prototype.fetchContent = function (parentKey) {
		//url空，表示改select控件不是需要动态改变可选项的
		if (this.url == null) return;
		//设定父节点
		if (isValid(parentKey)) {
			this.setParam("globe.tree.parent", parentKey);
		}
		//处理带入的参数
		var fp = this.getParam();
		var fu = (fp && fp != null)?this.url + fp:this.url;

		//通过http提交请求
		var http = new HttpObject();
		var ret = null;
		if (this.method == 'POST')
			ret = http.httpPostReturnMaps(this.url, fp);
		else
			ret = http.httpGetReturnMaps(fu);
			
		//处理获取的数据
		if (isValid(this.primaryKeyProperty) && (isValid(this.parentKeyProperty)||isValid(parentKey)) ) {
			//新增选项
			for (var i = 0; i < ret.length; i ++) {
				var prk = ret[i][this.primaryKeyProperty];
				
				var ptk = null;
				if (isValid(parentKey))
					ptk = parentKey;
				else
					ptk = ret[i][this.parentKeyProperty];
					
				var txt = prk
				if (isValid(this.textProperty)) {
					txt = ret[i][this.textProperty];
				} else if (typeof this.onContentBuild == "function") {
					txt = this.onContentBuild(ret[i]);
				}
				
				this.addNodeByPrimaryKey(prk, (isValid(ptk)?ptk:null), txt);
			}
				
			if (typeof this.onContentLoad == "function") {
				this.onContentLoad();
			}
		}
	}
	
	//depend
	Tree.prototype.dependOn = function (dependOnId, weakDepend, dependParam) {
		var obj = this;
		
		//不是弱依赖关系，将按钮disable
		if (!weakDepend) {
			obj.disabled = true;
		}
		
		var dependObj = document.getElementById(dependOnId);
		if (dependObj) {
			var change = function () {
				//以下是和控件相关的方法
				//如果依赖的控件值不为空
				if (dependObj.value && dependObj.value != "") {
					//允许改依赖开锁
					obj.free[dependOnId] = true;
					//参数带入
					if (dependParam) {
						obj.setParam(dependParam, dependObj.value);
					} else {
						obj.setParam(dependObj.name, dependObj.value);
					}
					//允许获取
					if (obj.isFree())
						obj.disabled = false;
				
				//如果依赖的控件值空
				} else {
					if (dependParam) {
						obj.removeParam(dependParam);
					} else {
						obj.removeParam(dependObj.name);
					}
					
					//如果弱依赖关系，那么则获取选项
					if (weakDepend) {
						obj.free[dependOnId] = true;
						if (obj.isFree())
							obj.disabled = false;
					//不是弱依赖关系，那么清除所有选项	
					} else {
						obj.free[dependOnId] = false;
						obj.disabled = true;
					}
				}
			}
			//IE
			if (document.all)
				dependObj.attachEvent("onchange", change);
			//FireFox
			else
				dependObj.addEventListener("change", change, false);
			change();
		}
	}
